package leetcode;

import leetcode.vo.ListNode;

/**
 * <p></p>
 *
 * @author bin.zhang
 * <p></p>
 * Revision History:
 * 2020/09/08, 初始化版本
 * @version 1.0
 **/
public class AddTwoNumbers {

	public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
		ListNode listNode = null;
		ListNode curso = null;
		int mod = 0;
		for(;;){
			if(l1 == null && l2 == null && mod == 0){
				break;
			}
			int l = 0;
			if(l1 != null){
				l += l1.val;
				l1 = l1.next;
			}
			if(l2 != null){
				l += l2.val;
				l2 = l2.next;
			}
			l+=mod;
			if(listNode == null){
				listNode = new ListNode(l % 10);
				curso = listNode;
			}else{
				curso.next = new ListNode(l % 10);
				curso = curso.next;
			}
			mod = l / 10;
		}
		return listNode;
	}

	public static void main(String[] args){
		ListNode two = new ListNode(1);
		ListNode five = new ListNode(9);
		five.next = new ListNode(9);


		ListNode result = new AddTwoNumbers().addTwoNumbers(two, five);
		System.out.println(result);
	}

}
